package com.ylsf.blog.controller;

import com.alibaba.fastjson.JSON;
import com.ylsf.blog.pojo.ArticleComment;
import com.ylsf.blog.service.DetailService;
import com.ylsf.blog.service.impl.DetailServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 展示文章详情控制类
 */
@WebServlet("/detail")
public class DetailServlet extends HttpServlet {
    private DetailService detailService=new DetailServiceImpl();
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        String articleId = request.getParameter("articleId");
        ArticleComment articleComment = detailService.displayArticleComment(Integer.valueOf(articleId));
        System.out.println(JSON.toJSONString(articleComment));
        response.getWriter().print(JSON.toJSONString(articleComment));
    }
}
